﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_IDAL;
using Zor_Tools;

namespace Zor_DAL
{
    public class YearTaxStat_DAL<T> where T : class
    {
       /// <summary>
       /// 获取年度税收统计表
       /// </summary>
       /// <param name="input"></param>
       /// <returns></returns>
        public static List<T> GetYearTaxStatList(string input)
        {
            var year = DateTime.Now.Year; //获取当前年份
            if (input == "" || input ==null )
            {
                year = DateTime.Now.Year; //获取当前年份
            }
            else
            {
                year = int.Parse(input);
            }
            var Sql = "select  sd.Dt_Name,sd.Dt_Id,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-01-01")) + "),0) as January, ";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-02-01")) + "),0) as February, ";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-03-01")) + "),0) as Marcy, ";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-04-01")) + "),0) as April,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-05-01")) + "),0) as May,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-06-01")) + "),0) as June,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-07-01")) + "),0) as July,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-08-01")) + "),0) as August,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-09-01")) + "),0) as September, ";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-10-01")) + "),0) as October,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-11-01")) + "),0) as November,";
            Sql += "ISNULL((select (Fcs+Grsds+Cjs+Jyffj+Zzs+Dfjyfj+Yhs+Sljj)  from Zor_PayTaxeCount where Stree_ID= sd.dt_Id and Type=2 and Pt_Date=" + TimeHelper.ToTimeStamp(DateTime.Parse(year + "-12-01")) + "),0) as December ";
            Sql += " from Sys_Department as sd ";
            Sql += " where sd.Dt_Level=3 ; ";         
            return DapperQuery<T>.DoQueryList(Sql, null);
        }
    }
}
